package com.example.studytest.Repository.Researcher;

import com.example.studytest.Entity.Researcher.T_researcher;
import com.example.studytest.Entity.User.T_user;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

public interface T_researcherRepository extends JpaRepository<T_researcher,Integer> {

    @Query(value = "SELECT email FROM t_researcher WHERE activate_code =:code ",nativeQuery = true)
    String findEmailByCode(@Param("code") String code);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update t_researcher set state='true' where email=:email",nativeQuery = true)
    void SetState(@Param("email") String email);

    @Query(value = "select * from t_researcher where email=:email", nativeQuery = true)
    T_researcher findByEmail(@Param("email")String email);

    @Query(value = "select * from t_researcher where t_researcher.email=:email1", nativeQuery = true)
    T_researcher findAllByEmail(@Param("email1") String email1);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update t_researcher set verification_code=:verification_code where email=:email",nativeQuery = true)
    void UpdateVerification_code(@Param("verification_code")String verification_code, @Param("email")String email );

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update t_researcher set pwd=:n_pwd where email=:email",nativeQuery = true)
    void UpdatePwd(@Param("n_pwd")String n_pwd, @Param("email")String email );

    @Query(value = "SELECT verification_code FROM t_researcher WHERE email =:email",nativeQuery = true)
    String findVcodeByEmail(@Param("email") String email);


}
